<?php

namespace core\bootstrap;

use hulang\tool\StrHelper;
use Shopwwi\LaravelCache\Cache;
use support\Db;
use Webman\Event\BootStrap;

class ListenDb extends BootStrap
{
    public static function start($worker)
    {
        Db::listen(function (\Illuminate\Database\Events\QueryExecuted $query) {
            if (
                !StrHelper::StartsWith(trim($query->sql), 'select')
                &&
                !StrHelper::StartsWith(trim($query->sql), '(select')
            ) {
                //清空缓存
                Cache::flush();
            }
        });
    }
}
